package bookstudytest.threadtest.Executor;

import bookstudytest.threadtest.implement.ThreadByCallable;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author heng.li
 * CachedThreadPool 一个任务创建一个线程
 */
public class CachedThreadPoolTest {
    /**
     * Future的cancel用于终端整在线程池中执行任务的线程
     *
     * @param args
     * @throws ExecutionException
     * @throws InterruptedException
     */
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newCachedThreadPool();
        Future<?> submit = executorService.submit(new ThreadByCallable());

        System.out.println(submit.cancel(true));
        System.out.println(submit.isCancelled());
        System.out.println("1111");
        System.out.println(submit.get());
        System.out.println(submit.isDone());
        executorService.shutdown();
    }
}
